//
//  MineTopCell.m
//  yunyan
//
//  Created by haichuang on 2018/2/26.
//  Copyright © 2018年 haichuang. All rights reserved.
//

#import "MineTopCell.h"

@implementation MineTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createTopCell];
       
    }
    return self;
}

-(void)createTopCell{
    WeakSelf;
    UIImageView * imageView = [[UIImageView alloc] init];
;
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo (weakSelf);
        make.bottom.equalTo (weakSelf.mas_bottom).offset (-30.0f);
    }];
    imageView.image = [UIImage imageNamed:@"my_bg_default"];
        

    _userImage = [[UIImageView alloc]init];
    [imageView addSubview:_userImage];
    [_userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo (weakSelf.mas_centerX);
        make.height.width.equalTo (@(70.f));
        make.top.equalTo (weakSelf.mas_top).offset (65.f);
    }];
    _userImage.image = [UIImage imageNamed:@"jjlin.jpg"];
    _userImage.layer.masksToBounds = YES;
    _userImage.layer.cornerRadius = 35.f;
    _userImage.userInteractionEnabled = YES;
    
   
    _nameLabel = [[UILabel alloc] init];
    [imageView addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo (_userImage.mas_centerX);
        make.top.equalTo (_userImage.mas_bottom).offset (12.f);
        make.height.equalTo (@(40.f));
    }];
    _nameLabel.text = @"昵称： 千与千寻";
    _nameLabel.font = [UIFont systemFontOfSize:18];
    _nameLabel.textColor = RGBA(51, 51, 51, 1);
  
    //做一个btn覆盖，扩大响应区
    UIButton * btn = [[UIButton alloc ]init];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo (_userImage);
        make.bottom.equalTo (_nameLabel.mas_bottom);
       
    }];
    [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //中间的分类
    UIView * minView = [[UIView alloc]init];
    [self addSubview:minView];
    [minView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo (weakSelf.mas_left).offset (20.0f);
        make.right.equalTo (weakSelf.mas_right).offset (-20.0f);
        
        make.top.equalTo (_nameLabel.mas_bottom).offset (0.f);
        make.height.equalTo (@(70.f));
    }];
  
    CGFloat width = (ScreenWidth-40)/3;
    
    
    _labelArr = @[@"收藏",@"随手拍",@"分享"];
    _imageArr = @[@"my_collection_default",@"my_photo_default",@"my_share_default"];
    for (int i = 0; i < _labelArr.count; i ++) {
        
        _optionView = [[OptionButton alloc]initWithFrame:CGRectMake(width * i, 0, width, 70)];
    
        [minView addSubview:_optionView];
        _optionView.titleLabel.text = _labelArr[i];
        _optionView.titleLabel.font = [UIFont systemFontOfSize:14.f];
        
        [_optionView.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        
            make.top.equalTo(_optionView.button.mas_bottom).offset(-2.f);
        
        }];
        [_optionView.button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",_imageArr[i]]] forState:UIControlStateNormal];
        _optionView.button.tag = 1000 +i;
        [_optionView.button addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
     
}

#pragma mark -Button
-(void)btnClicked:(UIButton *)sender{
    
   
    switch (sender.tag) {
        case 1000:
            
            if (_collectBtnBlock) {
                _collectBtnBlock();
            }
            
            break;
            
        case 1001:
            
            if (_pictureBtnBlock) {
                _pictureBtnBlock ();
            }
            break;
            
        case 1002:
            if (_shareBtnBlock) {
                _shareBtnBlock();
            }
            break;
            
       
        default:
            break;
    }
 
    
}

-(void)btnClicked{
    if (_imageBlock) {
        _imageBlock();
    }
}



@end
